package com.msmall.community.common;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.msmall.base.util.ConstantDB;
import com.msmall.community.common.model.Config;

public class Configuration {

	public static Map<String, Config> configs = new ConcurrentHashMap<String, Config>();
	
	public static final String SYSTEM_NAME = "systemName";
	
	public static final String SYSTEM_FILTER_CHARS = "filterChars";

	public static final String BBS_DEFAULT_BOARD_ID = "bbsDefaultBoardID";
	
	public static final String BBS_TOPIC_TITLE_MAX_CHARS = "topicTitleMaxChars";
	
	public static final String BBS_TOPIC_TITLE_MIN_CHARS = "topicTitleMinChars";
	
	public static final String BBS_TOPIC_CONTENT_MAX_CHARS = "topicContentMaxChars";
	
	public static final String BBS_TOPIC_CONTENT_MIN_CHARS = "topicContentMinChars";
	
	public static final String BBS_TOPIC_CONTENT_ABSTRACT_CHARS = "topicContentAbstractChars";
	
	public static final String BBS_THREAD_TITLE_MAX_CHARS = "threadTitleMaxChars";
	
	public static final String BBS_THREAD_TITLE_MIN_CHARS = "threadTitleMinChars";
	
	public static final String BBS_THREAD_CONTENT_MAX_CHARS = "threadContentMaxChars";
	
	public static final String BBS_THREAD_CONTENT_MIN_CHARS = "threadContentMinChars";
	
	public static final String SPACE_DIARY_TITLE_MAX_CHARS = "spaceDiaryTitleMaxChars";
	
	public static final String SPACE_DIARY_TITLE_MIN_CHARS = "spaceDiaryTitleMinChars";
	
	public static final String SPACE_DIARY_CONTENT_MAX_CHARS = "spaceDiaryContentMaxChars";
	
	public static final String SPACE_DIARY_CONTENT_MIN_CHARS = "spaceDiaryContentMinChars";
	
	public static final String SPACE_DIARY_REPLY_MIN_CHARS = "spaceDiaryReplyMinChars";
	public static final String SPACE_DIARY_REPLY_MAX_CHARS = "spaceDiaryReplyMaxChars";
	
	public static final String BBS_Audit_Module = "BBSAuditModule";
	
	public static final String BBS_Audit_First = "BBSAuditFirst";
	
	public static final String USER_NICKNAME_LENGTH_MAX = "userNicknameLengthMax";
	public static final String USER_NICKNAME_LENGTH_MIN = "userNicknameLengthMin";
	public static final String USER_PASSWORD_LENGTH_MAX = "userPasswordLengthMax";
	public static final String USER_PASSWORD_LENGTH_MIN = "userPasswordLengthMin";
	public static final String USER_USERNAME_LENGTH_MAX = "userUsernameLengthMax";
	public static final String USER_USERNAME_LENGTH_MIN = "userUsernameLengthMin";
	
	public static final String CONVENE_TITLE_MAX_CHARS = "conveneTitleMaxChars";
	public static final String CONVENE_TITLE_MIN_CHARS = "conveneTitleMinChars";
	public static final String CONVENE_CONTENT_MAX_CHARS = "conveneContentMaxChars";
	public static final String CONVENE_CONTENT_MIN_CHARS = "conveneContentMinChars";
	
	public static final String TEAM_NAME_MAX_CHARS = "teamNameMaxChars";
	public static final String TEAM_NAME_MIN_CHARS = "teamNameMinChars";
	public static final String TEAM_DESCRIPTION_MAX_CHARS = "teamDescriptionMaxChars";
	public static final String TEAM_DESCRIPTION_MIN_CHARS = "teamDescriptionMinChars";
	public static final String TEAM_DEFAULT_VICE_CHAIRMAN_COUNT = "teamDefaultViceChairmanCount";
	public static final String TEAM_DEFAULT_CREATE_COUNT = "teamDefaultCreateCount";
	
	public static final String WATERMARKER_TEXT = "watermarkerText";
	public static final String WATERMARKER_URL = "watermarkerUrl";
	public static final String WATERMARKER_IMAGE = "watermarkerImage";
	
	public static final String WISH_TIPS_LENGTH = "wishTipsLength";
	
	public static final String HOME_URL = "homeUrl";
	
	public static final String KLG_ARTICLE_REPLY_MAX_CHARS = "klgArticleReplyMaxChars";
	public static final String KLG_ARTICLE_REPLY_MIN_CHARS = "klgArticleReplyMinChars";
	public static final String KLG_ARTICLE_TITLE_MIN_CHARS = "klgArticleTitleMinChars";
	public static final String KLG_ARTICLE_TITLE_MAX_CHARS = "klgArticleTitleMaxChars";
	public static final String KLG_ARTICLE_CONTENT_MIN_CHARS = "klgArticleContentMinChars";
	public static final String KLG_ARTICLE_CONTENT_MAX_CHARS = "klgArticleContentMaxChars";
	public static final String KLG_ARTICLE_CONTENT_ABSTRACT_CHARS = "klgArticleContentAbstractChars";
	
	public static final String KLG_QUESTION_DEFAULT_SEGMENT = "klgQuestionDefaultSegment";
	public static final String KLG_QUESTION_ANSWER_MAX_CHARS = "klgQuestionAnswerMAXChars";
	public static final String KLG_QUESTION_ANSWER_MIN_CHARS = "klgQuestionAnswerMinChars";
	public static final String KLG_QUESTION_TITLE_MIN_CHARS = "klgQuestionTitleMinChars";
	public static final String KLG_QUESTION_TITLE_MAX_CHARS = "klgQuestionTitleMaxChars";
	public static final String KLG_QUESTION_CONTENT_MIN_CHARS = "klgQuestionContentMinChars";
	public static final String KLG_QUESTION_CONTENT_MAX_CHARS = "klgQuestionContentMaxChars";
	
	public static synchronized void add(Config config) throws Exception{
		try{
			configs.put(config.getConfigKey(), config);
		}catch(Exception e){
			throw new Exception("Load System Config Error!");
		}
	}
	
	public static synchronized void add(List list) throws Exception{
		try{
			if(list != null && list.size() > 0){
				for(int i = 0; i < list.size(); i++){
					Config config = (Config) list.get(i);
					add(config);
				}
			}
		}catch(Exception e){
			throw new Exception("Load System Config Error!");
		}
	}
	
	public static Config get(String key){
		return configs.get(key);
	}
	
	public static String getValue(String key){
		Config config = get(key);
		if(config == null || config.getEnabled().compareTo(ConstantDB.UNAVALIABLE) == 0)
			return null;
		return config.getConfigValue();
	}
	
	public static int getIntegerValue(String key){
		String value = getValue(key);
		try{
			return Integer.valueOf(value);
		}catch(Exception e){
			return 0;
		}
	}
}
